import 'package:flutter/material.dart';
import 'package:flutter_mode/utils.dart';

class Todo {
  final String title;
  final String description;

  Todo(this.title, this.description);
}

class TodosScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var list = List.generate(
        20,
        (index) => Todo(
              'Todo $index',
              'A description of what needs to be done for Todo $index',
            ));
    var listView = ListView.builder(itemBuilder: (context, index) {
      return ListTile(
        title: Text(list[index].title),
        onTap: () {
          pushMaterial(context, DetailScreen(list[index]));
        },
      );
    });
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('构造函数传递数据'),
        leading: BackButton(),
      ),
      body: listView,
    );
  }
}

class DetailScreen extends StatelessWidget {
  final Todo todo;

  DetailScreen(this.todo);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('${todo.title}'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Text('${todo.description}'),
      ),
    );
  }
}
